/*
 *  Copyright (C) 2010 Matthias Buch-Kromann <mbk.isv@cbs.dk>
 * 
 *  This file is part of the MatrixParser package.
 *  
 *  The MatrixParser program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 * 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.osdtsystem.matrixparser.featureextraction;

import java.util.Collection;
import org.osdtsystem.matrixparser.data.CONLLSentence;
import org.osdtsystem.matrixparser.features.FeatureVector;
import org.osdtsystem.matrixparser.parsers.ParsingModel;
import org.osdtsystem.matrixparser.parsers.output.DependencyTree;

/**
 *
 * @author Matthias Buch-Kromann <mbk.isv@cbs.dk>
 */
public class UnionExtractor extends AbstractFeatureExtractor
        implements FirstOrderExtractorUnlabelled, FirstOrderExtractorLabelled, HigherOrderExtractor {
    Collection<FirstOrderExtractorUnlabelled> firstOrderUnlabelled;
    Collection<FirstOrderExtractorLabelled> firstOrderLabelled;
    Collection<FeatureExtractor> higherOrder;

    public UnionExtractor(ParsingModel model, FeatureExtractorRegistry extractors) {
        super(model);
        firstOrderUnlabelled = extractors.firstOrderUnlabelled();
        firstOrderLabelled = extractors.firstOrderLabelled();
        higherOrder = extractors.higherOrder();
    }

    public void extract(FeatureVector fv, DependencyTree tree, int node) {
        for (FeatureExtractor extractor : firstOrderUnlabelled)
            extractor.extract(fv, tree, node);
        for (FeatureExtractor extractor : firstOrderLabelled)
            extractor.extract(fv, tree, node);
        for (FeatureExtractor extractor : higherOrder)
            extractor.extract(fv, tree, node);
    }

    public void extractUnlabelled(FeatureVector fv, CONLLSentence sentence, int head, int dep) {
        for (FirstOrderExtractorUnlabelled extractor : firstOrderUnlabelled)
            extractor.extractUnlabelled(fv, sentence, head, dep);
    }

    public void extractLabelled(FeatureVector fv, CONLLSentence sentence, int label,
            int node, boolean RA, boolean child) {
        for (FirstOrderExtractorLabelled extractor : firstOrderLabelled)
            extractor.extractLabelled(fv, sentence, label, node, RA, child);
    }

    public void extractHigherOrder(FeatureVector fv, DependencyTree tree, int node) {
        for (FeatureExtractor extractor : higherOrder)
            extractor.extract(fv, tree, node);
    }
}
